package com.gluck.cases.common.utils.utils;

import org.springframework.http.HttpStatus;

import java.io.Serializable;

/**
 * @ClassName BizResult
 * @Desc 业务返回
 * @Author I am Gluck
 * @Date 2022/5/2 - 1:10 上午
 **/
public class BizResult<T> implements Serializable {

    private static final long serialVersionUID = -2621971349417146220L;

    protected boolean success;

    protected String errorCode;

    protected String errorMsg;

    protected T result;

    protected String successCode;

    protected String successMsg;

//    protected boolean needRetry;


    public static <T> BizResult<T> newSuccessResult(T t){
        BizResult<T> result = new BizResult<T>();
        result.setSuccess(true);
//        result.setNeedRetry(false);
        result.setResult(t);
        result.setSuccessCode(String.valueOf(HttpStatus.OK.value()));
        return result;
    }

    public static <T> BizResult<T> newFailResult(String errorCode, String errorMsg){
        BizResult<T> result = new BizResult<T>();
        result.setSuccess(false);
        result.setErrorCode(errorCode);
        result.setErrorMsg(errorMsg);
        return result;
    }

    public static <T> BizResult<T> newResult(){
        return new BizResult<>();
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public T getResult() {
        return result;
    }

    public void setResult(T result) {
        this.result = result;
    }

    public String getSuccessCode() {
        return successCode;
    }

    public void setSuccessCode(String successCode) {
        this.successCode = successCode;
    }

    public String getSuccessMsg() {
        return successMsg;
    }

    public void setSuccessMsg(String successMsg) {
        this.successMsg = successMsg;
    }

//    public boolean isNeedRetry() {
//        return needRetry;
//    }
//
//    public void setNeedRetry(boolean needRetry) {
//        this.needRetry = needRetry;
//    }

    @Override
    public String toString() {
        return "BizResult{" +
                "success=" + success +
                ", errorCode='" + errorCode + '\'' +
                ", errorMsg='" + errorMsg + '\'' +
                ", result=" + result +
                ", successCode='" + successCode + '\'' +
                ", successMsg='" + successMsg + '\'' +
                '}';
    }
}
